package edu.API;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

public class DatePra {
    public static void main(String[] args) throws ParseException {
        //1970-1-1 0 开始计算的毫秒值
        long timeMillis = System.currentTimeMillis();
        System.out.println("timeMillis = " + timeMillis);
        //默认获取当前系统时间
        Date date = new Date();
        System.out.println("date = " + date);
        //自定义时间
        Date date2 = new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000);
        //日期格式化  DateFormat   ----> SimpleDateFormat
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String s = dateFormat.format(date);
        System.out.println("s = " + s);
        //字符串  --->  date
        String s2 = "2020-05-12";
        SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = dateFormat2.parse(s2);
        System.out.println("parse = " + parse);
        //Calendar   日历
        Calendar calendar = Calendar.getInstance();
        calendar.set(2020,05,12,12,25,56);
        Date time = calendar.getTime();
        System.out.println("time = " + time);

        //LocalDate   LocalTime    LocalDateTime
        LocalDate localDate = LocalDate.now();
        System.out.println("localDate = " + localDate);
        LocalDate localDate1 = LocalDate.of(2021, 05, 18);
        System.out.println("localDate1 = " + localDate1);
        //其他操作自行查看

        //格式化    目标格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd");
        String s1 = localDate.format(formatter);
        System.out.println("s1 = " + s1);

        Runtime runtime = Runtime.getRuntime();
        //获取jvm最大内存   b
        long maxMemory = runtime.maxMemory();
        System.out.println("maxMemory = " + maxMemory);
        //获取jvm空闲内存
        long freeMemory = runtime.freeMemory();
        System.out.println("freeMemory = " + freeMemory);
        String s3 = "s";
        for (int i = 0; i < 1000; i++) {
            s3 += i;
        }
        long freeMemory2 = runtime.freeMemory();
        System.out.println("freeMemory2 = " + freeMemory2);

        //gc   garbage  collector   垃圾回收   jvm    垃圾回收机制
        //runtime.gc();


    }
}
/**
 *
 * 定时器：Timer
 * Runtime:
 * System:
 * 集合：
 *      数组：存储多个数据   数组长度不能改变
 *      动态扩容
 *      list 、set 、map
 *      list: 列表
 *
 * 异常：
 * io:
 * java8新特性：
 * lambda:
 *
 */
